package com.rams.jhms.gui.datamodels;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.rams.jhms.Config;
import com.rams.jhms.fs.FSFile;

public class FSTableModel extends AbstractTableModel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6446012996559845569L;
	private ArrayList<String> columnsName = new ArrayList<String>();
	private List<FSFile> files = new ArrayList<FSFile>();
	
	public FSTableModel() {
		columnsName.add(Config.local.fsTableColumnFilename());
		columnsName.add(Config.local.fsTableColumnBitrate());
		columnsName.add(Config.local.fsTableColumnDuration());
	}
	
	public String getColumnName(int index) {
		return columnsName.get(index);
	}
	
	public int getRowCount() {
		return files.size();
	}

	public int getColumnCount() {
		return columnsName.size();
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		switch(columnIndex) {
			case 0: 
				return files.get(rowIndex).getName();
			case 1: 
				return files.get(rowIndex).getTrackBitrate();
			case 2:
				return files.get(rowIndex).getFormatedTrackLength();
			default : 
				return "";
		}
	}

	public void setTableData(List<FSFile> files) {
		this.files = files;
		fireTableDataChanged();
	}
	
	public FSFile getDataAt(int index) {
		return files.get(index);
	}
}
